package cn.yunyichina.openapi.sdk.config;

import java.io.InputStream;
import java.util.Properties;


/**
 * 配置项
 *
 * @author zhangkewen
 */
public class OpenApiConfig {

    static OpenApiConfig config;

    public static OpenApiConfig getConfig() {
        if (config == null) {
            config = new OpenApiConfig();
        }
        return config;
    }

    /*商户唯一标记*/
    private String appId;

    /*格式*/
    private String format;

    /*版本*/
    private String v;

    /*验签的作用  1 AES+MD5  2 RSA*/
    private Integer signType;

    /*开放性接口地址*/
    private String openApiUrl;

    /*aes签名Key*/
    private String signKey;

    /*广州云医生科技公钥*/
    private String yunyichinaPublicKey;

    /*商户私钥*/
    private String merchantPrivateKey;

    /*商户公钥*/
    private String merchantPublicKey;

    public String getAppId() {
        return appId;
    }

    public void setAppId(String appId) {
        this.appId = appId;
    }

    public String getFormat() {
        return format;
    }

    public void setFormat(String format) {
        this.format = format;
    }

    public String getV() {
        return v;
    }

    public void setV(String v) {
        this.v = v;
    }

    public Integer getSignType() {
        return signType;
    }

    public void setSignType(Integer signType) {
        this.signType = signType;
    }

    public String getOpenApiUrl() {
        return openApiUrl;
    }

    public void setOpenApiUrl(String openApiUrl) {
        this.openApiUrl = openApiUrl;
    }

    public String getSignKey() {
        return signKey;
    }

    public void setSignKey(String signKey) {
        this.signKey = signKey;
    }

    public String getYunyichinaPublicKey() {
        return yunyichinaPublicKey;
    }

    public void setYunyichinaPublicKey(String yunyichinaPublicKey) {
        this.yunyichinaPublicKey = yunyichinaPublicKey;
    }

    public String getMerchantPrivateKey() {
        return merchantPrivateKey;
    }

    public void setMerchantPrivateKey(String merchantPrivateKey) {
        this.merchantPrivateKey = merchantPrivateKey;
    }


    public String getMerchantPublicKey() {
        return merchantPublicKey;
    }

    public void setMerchantPublicKey(String merchantPublicKey) {
        this.merchantPublicKey = merchantPublicKey;
    }

    /**
     * 初始化配置
     *
     * @throws Exception
     */
    public void initOpenApiConfig() throws Exception {
        Properties pro = new Properties();

        try (InputStream inputStream = ClassLoader.getSystemClassLoader().getResourceAsStream("yytopenapi.properties")) {
            pro.load(inputStream);
        }

        this.openApiUrl = pro.getProperty("yyt.open_api_url");
        this.appId = pro.getProperty("yyt.app_id");
        this.format = pro.getProperty("yyt.format");
        this.v = pro.getProperty("yyt.v");
        this.signType = Integer.parseInt(pro.getProperty("yyt.sign_type"));
        this.signKey = pro.getProperty("yyt.sign_key");
        this.yunyichinaPublicKey = pro.getProperty("yyt.yunyichina_public_key");
        this.merchantPrivateKey = pro.getProperty("yyt.merchant_private_key");
        this.merchantPublicKey = pro.getProperty("yyt.merchant_public_key");
    }

}
